//
//  TWorkListVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/9.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "TWorkListVC.h"
#import "SYRequestAPI+Teach.h"
#import "SYKaoShiJuanDetailsView.h"

@interface TWorkListVC ()<LWQSwichButtonDelegate,CellClickDelegate,ResultStatisticsDelegate>{
    int currentIndex;
}
@property (nonatomic, strong) UIView *baseView;
@property (nonatomic, strong) SYKaoShiJuanDetailsView *kaoqingView;
@end

@implementation TWorkListVC
- (instancetype)initWithWight:(CGFloat)w  andClassID:(NSString *)classID andPaperID:(nonnull NSString *)paperID{
    if ([super init]) {
        self.classID = classID;
        self.paperID = paperID;
        self.mainw = w;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    _mainw = MAINW;
//#pragma mark - 目前每次都要使用
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeView:) name:@"ChangeCellSpaNotice" object:nil];
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeView:) name:@"TeachChangeNotice" object:nil];
    
}
#pragma mark - 这个基本每个类都要用
//- (void)changeView:(NSNotification *)info{
//    int type = [[info.userInfo objectForKey:@"Type"] intValue];
//    _mainw = [PublickFunctionObject currentScreenSize:type];
//
//    self.mainScrollView.contentOffset = CGPointMake(_mainw*currentIndex, 0);
//
//    [_submitDetailView.tableList reloadData];
//}
- (LWQSwichButtonView *)navView{
    if (!_navView) {
        NSMutableArray *array = [NSMutableArray new];
        [array addObject:@"上交详情"];
        [array addObject:@"结果统计"];
        [array addObject:@"作业详情"];
        LWQSwichButtonView *view = [[LWQSwichButtonView alloc]initWithFrame:CGRectMake(0, 0,_mainw, 44) andArray:array];
        view.delegate = self;
        _navView = view;
    }
    return _navView; 
}
//- (UIScrollView *)mainScrollView{
//    if (!_mainScrollView) {
//        UIScrollView *view = [[UIScrollView alloc]init];
//        view.frame = CGRectMake(0, 44, _mainw, self.view.frame.size.height-84);
//        view.contentSize = CGSizeMake(_mainw*3, 0);
//        view.showsHorizontalScrollIndicator = YES;
//        view.showsVerticalScrollIndicator = NO;
//        view.pagingEnabled = YES;
//        view.scrollEnabled = NO;
//        _mainScrollView = view;
//    }
//    return _mainScrollView;
//}
- (ShangJiaoXiangQingView *)SJXQView{
    if (!_SJXQView) {
        ShangJiaoXiangQingView *view = [[ShangJiaoXiangQingView alloc]init];
        view.frame = CGRectMake(0, 0, _mainw, self.view.frame.size.height);
        view.backgroundColor = [UIColor whiteColor];
        view.mainDelegate = self;
        view.tag = 1;
        _SJXQView = view;
    }
    return _SJXQView;
}
- (ResultStatisticsView *)RSView{
    if (!_RSView) {
        ResultStatisticsView *view = [[ResultStatisticsView alloc]initWithFrame:self.view.bounds andClassID:self.classID andePaperID:self.paperID];
        view.frame = CGRectMake(_mainw, 0, _mainw, self.view.frame.size.height);
        view.backgroundColor = [UIColor whiteColor];
        view.mainDelegate = self;
        view.tag = 2;
        _RSView = view;
    }
    return _RSView;
}
- (SYKaoShiJuanDetailsView *)kaoqingView{
    if (!_kaoqingView) {
        SYKaoShiJuanDetailsView *view = [[SYKaoShiJuanDetailsView alloc]init];
//        view.frame = CGRectMake(_mainw*2, 0, _mainw, self.view.frame.size.height);
        view.backgroundColor = [UIColor whiteColor];
        view.tag = 3;
        view.topView.hidden = YES;
        view.chakanBtn.hidden = YES;
        _kaoqingView = view;
    }
    return _kaoqingView;
}

/**
 撑起scrollView的baseView

 @return nil
 */
- (UIView *)baseView{
    if (!_baseView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = [UIColor whiteColor];
        _baseView = view;
    }
    return _baseView;
}
- (void)initSubView{
    [self.view addSubview:self.navView];
    [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
//    [self.view addSubview:self.mainScrollView];
//    [_mainScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(@0);
//        make.right.equalTo(@0);
//        make.top.equalTo(@44);
//        make.bottom.equalTo(@0);
//    }];
//    [self.mainScrollView addSubview:self.baseView];
//    [_baseView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(self->_mainScrollView);
//    }];
    _viewArray = [NSMutableArray new];
    [self.view addSubview:self.SJXQView];
    [_SJXQView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@44);
        make.height.equalTo(self.view.mas_height);
    }];
    _SJXQView.hidden = NO;
    [_viewArray addObject:_SJXQView];
    
    [self.view addSubview:self.RSView];
    _RSView.hidden = YES;
    [_RSView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(@44);
        make.height.equalTo(self.view.mas_height);
    }];
    [_viewArray addObject:_RSView];
    
    [self.view addSubview:self.kaoqingView];
    _kaoqingView.hidden = YES;
    [_kaoqingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(@44);
        make.height.equalTo(self.view.mas_height);
    }];
    [_viewArray addObject:_kaoqingView];
    [_kaoqingView requestDataListTemplateId:self.paperID];
}
- (void)initOption{
    
}
- (void)layout{
    
}
- (void)back{
    [UIView animateWithDuration:0.5 animations:^{
        CGRect rect = self.view.frame;
        rect.origin.x = APP_WIDTH-200;
        self.view.frame = rect;
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        [[NSNotificationCenter defaultCenter]removeObserver:self name:@"TeachChangeNotice" object:nil];
    }];
    [self sendShowView];
}
- (void)scrollViewChangeButtom:(int)index{
    for (int i = 0; i<3; i++) {
        UIView *view = _viewArray[i];
        if (i == index) {
            view.hidden = NO;
        }else{
            
            view.hidden = YES;
        }
    }

}
//通知显示界面
- (void)sendShowView{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ShowView" object:nil];
}
#pragma mark - 添加自视图的显示
- (void)checkDetail:(JiaoXueZuoYeShangJiaoXiangQingModel *)model{
    //点击了查看跳转
    
    _lookDetailView = [[SJDLookDetailVC alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) andPaperFilePath:model.paperFilePath];
    _lookDetailView.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:_lookDetailView];
    [_lookDetailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
//    [UIView animateWithDuration:0.5 animations:^{
//        self->_lookDetailView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
//    }];
//
//    [_WPView.tableList reloadData];
}
#pragma mark - 添加结果统计的子视图
- (void)rSD:(NSString *)paperQuestionID{
    _submitDetailView = [[RSDetailView alloc]initWithFrame:CGRectMake(0, 0, MAINW, self.view.frame.size.height) addClassID:self.classID addPaperID:self.paperID andPaperQuestionId:paperQuestionID];
//    _submitDetailView.studentID =
    [self.view addSubview:_submitDetailView];
    [_submitDetailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
//    [UIView animateWithDuration:0.5 animations:^{
//        self->_submitDetailView.frame = CGRectMake(0, 0, MAINW, self.view.frame.size.height);
//    }];
    
}
- (void)anXueShengTongJiDelegate:(NSString *)noID{
    //按照学生统计
    NSDictionary *parame = @{@"studentId":noID,
                             @"templateId":self.paperID};
    [MBProgressHUD mj_showMessage:nil toView:self.view];
    [SYRequestAPI sy_getClassServiceStatisticsByStudent:parame success:^(id  _Nonnull responseObject) {
        NSLog(@"按照学生统计 %@",responseObject);
        [self addAnZhaoXueShengTongJiImagePath:[[responseObject objectForKey:@"data"] objectForKey:@"paperFilePath"]];
        [MBProgressHUD mj_hideHUDForView:self.view];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self.view];
    }];
    
   
}
#pragma mark - 得到z按照学生统计的图片路径
- (void)addAnZhaoXueShengTongJiImagePath:(NSString *)paperPath{
    _lookDetailView = [[SJDLookDetailVC alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) andPaperFilePath:paperPath];
    _lookDetailView.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:_lookDetailView];
    [_lookDetailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
//    [UIView animateWithDuration:0.5 animations:^{
//        self->_lookDetailView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
//    }];
}
- (void)dealloc{
//    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"TWCellNotice" object:nil];
}


@end
